{/* LAYOUT模板 */}
<layout name="layout"/>
{/* LAYOUT模板 */}
{/* import Js,Css */}
<js href="__JS__/admin/listTable.js"/>
<js href="__JS__/admin/js.util.js"/>
<css href="__CSS__/admin/common.css"/>
<js href="__JS__/admin/js.selectzone.js"/>	
<css href="__CSS__/jquery-ui.css" />
<js href="__JS__/core/jquery-ui.1.10.4.js" />
<js href="__JS__/core/jquery.form.js" />
<js href="__JS__/core/plugins.js"/>
<!--ueditor js-->
<script type="text/javascript" charset="utf-8" src="__PLUGS__/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="__PLUGS__/ueditor/ueditor.all.min.js"> </script>
<script type="text/javascript" charset="utf-8" src="__PLUGS__/ueditor/lang/zh-cn/zh-cn.js"></script>
{/* import js,css */}

<include file="Template:position"/>
<div id="loading" style="z-index:10000;"><!--#loading#--></div>


<style>
#tab{margin-left:2px; margin-bottom:-2px;}#tab ul li{list-style:none;}#tab li{border:1px solid #b5e2f3;border-bottom:0px;float:left;width:100px;height:25px;margin:0 -1px;background:#F1FEF3;padding:9px 0 0 0;text-align:center;color:#33a3dc;cursor:pointer;}#tab ul{width:800px;height:36px;border-bottom:1px solid #b5e2f3;/*border-bottom:1px solid #b5e2f3;*/}#tab #selected{background:#FFF!important;border-bottom:2px solid #FFF!important;}ul{margin:-1px;}#cate1,#cate2, #cate3, #cate4, #cate5{clear:both;height:300px;background:#FFFFFF;width:800px;height:100px;padding:25px;height:auto;border:1px solid #b5e2f3;}
</style>
<form id="add-article-form" name="theForm" method="post" action="__URL__/<if condition="$act eq 'add_article'">add_article_ok<else/>mod_article_ok</if>" enctype="multipart/form-data">
	<div class="mauto" style="width:80%">
		<div id="tab" >
			<ul>
				<li tar="cate1" id="selected">通用信息</li>
				<li tar="cate2">文章内容</li>
				<li tar="cate3">关联商品</li>
			</ul>
		</div>
		<div>
			<div id="cate1" >
				<table width="90%">
					<tbody>
						<tr>
							<td class="narrow-label">文章标题</td>
							<td><input type="text" class="qs-input" name="title" size="40" maxlength="60" value="{$article_info.title}"><span class="require-field">*</span></td>
						</tr>       
						<tr>
							<td class="narrow-label">文章分类 </td>
							<td>
								<select class="qs-select" name="article_cat" onchange="catChanged()">
									<volist name="articleCatList" id="articleCat">
									<option value="{$articleCat.cat_id}" cat_type="{$articleCat.cat_type}" <if condition="$article_info['cat_id'] eq $articleCat['cat_id']">selected</if>>{$articleCat.cat_name}</option>
									</volist>      
								</select>
								<span class="require-field">*</span>
							</td>
						</tr>
						<tr>
							<td class="narrow-label">文章重要性</td>
							<td>
								<input type="radio" name="article_type"  value="0" <if condition="$article_info['article_type'] eq 0">checked</if>>普通      
								<input type="radio" name="article_type" value="1" <if condition="$article_info['article_type'] eq 1">checked</if>>置顶       
								<span class="require-field">*</span>        
							</td>
						</tr>
						<tr>
							<td class="narrow-label">是否显示</td>
							<td>
								<input type="radio" name="is_open" value="1" <if condition="$article_info['is_open'] eq 1">checked</if> > 显示      
								<input type="radio" name="is_open" value="0" <if condition="$article_info['is_open'] eq 0">checked</if> > 不显示<span class="require-field">*</span>        
							</td>
						</tr>
						<tr>
							<td class="narrow-label">文章作者</td>
							<td><input type="text" class="qs-input" name="author" maxlength="60" value="{$article_info.author}"></td>
						</tr>
						<tr>
							<td class="narrow-label">作者email</td>
							<td><input type="text" class="qs-input" name="author_email" maxlength="60" value="{$article_info.author_email}"></td>
						</tr>
						<tr>
							<td class="narrow-label">关键字</td>
							<td><input type="text" class="qs-input" name="keywords" maxlength="60" value="{$article_info.keywords}"></td>
						</tr>
						<tr>
							<td class="narrow-label">文章排序</td>
							<td>
								<input type="text" class="qs-input" name="sort_order" maxlength="60" value="{$article_info.sort_order}">大于1的数字
							</td>
						</tr>
						<tr>
							<td class="narrow-label">网页描述</td>
							<td><textarea name="description" class="qs-input" id="description" cols="40" rows="5">{$article_info.description}</textarea></td>
						</tr>
						<tr>
							<td class="narrow-label">外部链接</td>
							<td><input name="link_url" class="qs-input" type="text" id="link_url" value="http://{$article_info.link}" maxlength="60"></td>
						</tr>
						<tr>
							<td class="narrow-label">上传文件</td>
							<td>
								<input type="file" name="file">
								<span class="narrow-label">
									或输入文件地址         
									<input name="file_url" class="qs-input" type="text" value="{$article_info.file_url}" size="30" maxlength="255">
								</span>
							</td>
						</tr>
					</tbody>
				</table>
			</div>
			<div id="cate2" style="display:none;">
				<div>
				    <script id="editor" type="text/plain" name="content" style="width:100%;height:500px;z-index:1;position:relative;">{$content}</script>
				</div>
			</div>
			<div id="cate3" style="display:none;">
				<table width="90%">
					<!-- 商品搜索 -->
					<tbody>
						<tr>
							<td colspan="5">
								<img src="__PUBLIC__/image/admin/icon_search.gif" width="26" height="22" border="0" alt="SEARCH">
								<!-- 分类 -->
								<select name="cat_id">
									<option value="0">所有分类</option>
									<volist name="goodsCatList" id="goodsCat">
									<option value="{$goodsCat.cat_id}">{$goodsCat.cat_name}</option>									
									</volist>
								</select>
								<!-- 品牌 -->
								<select name="brand_id">
									<option value="0">所有品牌</option>
									<volist name="brandList" id="brand">
									<option value="{$brand.brand_id}">{$brand.brand_name}</option>
									</volist>
								</select>
								<!-- 关键字 -->
								<input type="text" name="keyword" size="30">
								<input type="button" value=" 搜索 " onclick="searchGoods()" />
							</td>
							<td>
							</td>
						</tr>
						<!-- 商品列表 -->
						<tr>
							<th></th>
							<th>操作</th>
							<th></th>
						</tr>
						<tr>
							<td width="45%" align="center">
								<select name="source_select" size="20" style="width:90%" ondblclick="sz.addItem(false, 'add_link_goods', articleId)" multiple="true">
								</select>
							</td>
							<td align="center">
								<p><input type="button" value=">>" onclick="sz.addItem(true, 'add_link_goods', articleId)" /></p>
								<p><input type="button" value=">" onclick="sz.addItem(false, 'add_link_goods', articleId)" /></p>
								<p><input type="button" value="<" onclick="sz.dropItem(false, 'drop_link_goods', articleId)" /></p>
								<p><input type="button" value="<<" onclick="sz.dropItem(true, 'drop_link_goods', articleId)" /></p>
							</td>
							<td width="45%" align="center">
								<select name="target_select" multiple="true" size="20" style="width:90%" ondblclick="sz.dropItem(false, 'drop_link_goods', articleId)">
									<volist name="goods_article_list" id="goods_article">
										<option value="{$goods_article.goods_id}" id="">{$goods_article.goods_name}</option>
									</volist>
								</select>
							</td>
						</tr>
					</tbody>
				</table>
			</div>
		</div>
		<div class="button-div">
			<input type="hidden" name="act" value="insert">
			<input type="hidden" name="old_title" value="{$article_info.title}">
			<input type="hidden" name="id" value="{$article_info.article_id}">
			<input id="submit-btn" type="button" class="qs-btn" value=" 确定 " />
			<input type="reset" class="qs-btn" value=" 重置 " />
		</div>
	</div>
</form>

<script>
	/**
	* 考虑到tab和pane有可能被动态的添加和删除，
	* 所以每次都废点时间去查找先前被激活的tab
	*/
	var tab = function(tabId,activeId){
		$("#"+tabId).delegate("li:not(#"+activeId+")","click",function(){
			$("#"+$("#"+activeId).attr("tar")).css("display","none");
			$("#"+activeId).removeAttr("id");			 
			$(this).attr("id",activeId);
			$("#"+$(this).attr("tar")).css("display","block");
		});
	};
	tab("tab","selected");
	/*ajax添加文章*/
	$(document).ready(function(){
		$('#submit-btn').click(function(){
			var datas	=	$('#add-article-form').QVal();
			if(datas.title == ''){
				$('#loading').QLoading({img:'sad',text:'文章标题不能为空',modal:false,status:'open',time:1});
				return;
			}
			$('#add-article-form').ajaxSubmit({
				url:'__URL__/<if condition="$act eq 'add_article'">add_article_ok<else/>mod_article_ok</if>',
				type:'post',
				//dataType:'json',
				beforeSubmit:function(){
					$('#loading').QLoading({text:'提交中...',modal:false,status:'open'});
				},
				success:function(msg){
					if(msg.data == '1'){
						$('#loading').QLoading({img:'happy',text:msg.info,modal:false,status:'close',time:1.5});						
					}
					else{
						$('#loading').QLoading({img:'sad',text:msg.info,modal:false,status:'close',time:1.5});
						//刷新当前页面
 						//location.reload(); 
					}
				}
			});
		});
	});
</script>


<script>
	var articleId = <if condition="$article_info['article_id']">{$article_info.article_id}<else/>0</if>;
	var elements  = document.forms['theForm'].elements;
	var sz        = new SelectZone(1, elements['source_select'], elements['target_select'], '');
	var sz        = new SelectZone(1, elements['source_select'], elements['target_select'], '');
	onload = function(){
		// 开始检查订单
		//startCheckOrder();
	}

	function validate(){
		var validator = new Validator('theForm');
		validator.required('title', no_title);
		validator.isNullOption('article_cat',no_cat);
		return validator.passed();
	}

	function showNotice(objId){
		var obj = document.getElementById(objId);
		if (obj){
			if (obj.style.display != "block"){
				obj.style.display = "block";
			}
			else{
				obj.style.display = "none";
			}
		}
	}

	function searchGoods(){
		var elements  = document.forms['theForm'].elements;
		var filters   = new Object;
		filters.cat_id = elements['cat_id'].value;
		filters.brand_id = elements['brand_id'].value;
		filters.keyword = Utils.trim(elements['keyword'].value);
		sz.loadOptions('get_goods_list', filters);
	}


	/**
	 * 选取上级分类时判断选定的分类是不是底层分类
	 */
	function catChanged(){
		var obj = document.forms['theForm'].elements['article_cat'];

		cat_type = obj.options[obj.selectedIndex].getAttribute('cat_type');
		if (cat_type == undefined){
			cat_type = 1;
		}

		if ((obj.selectedIndex > 0) && (cat_type == 2 || cat_type == 4)){
			alert(not_allow_add);
			obj.selectedIndex = 0;
			return false;
		}

		return true;
	}
</script>

<script type="text/javascript">
    //实例化编辑器
    var ue = UE.getEditor('editor');
</script>









